<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/topjui/themes/default/topjui.bluelight.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <link type="text/css" href="/topjui/css/myui.css" rel="stylesheet"/>
    <script type="text/javascript" src="/static/public/js/topjui.config.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="/static/plugins/layui/layui.js" charset="utf-8"></script>
    <script src="/easyui/jquery.min.js"></script>
    <script src="/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/topjui/js/sysutils.js"></script>
</head>

<body>

<table id="rowgrid" class="topjui-datagrid" data-options="fit:true,border:false"></table>

<script type="text/javascript" charset="utf-8" th:inline="none">
    var listgrid;
    $(function(){
        listgrid = $('#rowgrid').datagrid({
            url:"/contract/list",
            method:'get',
            fit : true,
            //fitColumns : true,
            striped : true,
            border : false,
            pagination : true,
            idField : 'id',
            pageSize : 20,
            pageList : [ 20, 50, 100 ],
            sortName : 'id',
            sortOrder : 'desc',
            checkOnSelect : true,
            selectOnCheck : true,
            nowrap : false,
            queryParams:{
                del:1
            },
            frozenColumns:[[
                {
                    field:'id',
                    title:'编号',
                    width:50,
                    checkbox : true
                }, {
                    field : 'action',
                    title : '操作',
                    width : 60,
                    align:'center',
                    formatter : function(value, row, index) {
                        return formatString(
                            '<img onclick="list_deleteFun(\'{0}\');" src="{1}" style="cursor:pointer"/>',
                             row.code, '/static/admin/images/edit_remove.png');
                    }
                },{
                    field:'code',
                    title:'合同编号',
                    sortable:true,
                    width:120
                }, {
                    field:'name',
                    title:'合同名称',
                    width:160
                }, {
                    field:'type',
                    title:'合同类型',
                    width:100
                }, {
                    field:'introtype',
                    title:'行业分类',
                    width:100
                }, {
                    field:'status',
                    title:'状态',
                    width:90,
                    align:'center',
                    formatter : function(value, row, index) {
                        if(value == '1'){
                            return '<span style="color:gold">待签合同</span>';
                        }else if(value=='2'){
                            return '<span style="color:green">签订合同</span>'
                        }else if(value=='3'){
                            return '<span style="color:green">发货合同</span>'
                        }else if(value=='4'){
                            return '<span style="color:green">收款合同</span>'
                        }else{
                            return '<span style="color:blue">完成合同</span>';
                        }
                    }
                }
            ]],
            columns:[[
                {
                    field:'customerid',
                    title:'需方信息',
                    hidden:true
                },{
                    field:'customername',
                    title:'需方名称',
                    width:160
                },{
                    field:'signmanid',
                    title:'销售人员ID',
                    hidden:true
                }, {
                    field:'signman',
                    title:'销售人员',
                    width:160
                }, {
                    field:'crtime',
                    title:'签订日期',
                    width:160
                }, {
                    field:'total',
                    title:'总金额',
                    width:80
                }, {
                    field:'paytype',
                    title:'付款方式',
                    width:160
                }, {
                    field:'receivables',
                    title:'应收款',
                    width:160
                }, {
                    field:'payment',
                    title:'已收款',
                    width:160
                }, {
                    field:'lastpaytime',
                    title:'最后付款时间',
                    width:160
                }, {
                    field:'address',
                    title:'存放地方',
                    width:160
                }
            ]],
            toolbar:[{
                text:'查询',
                iconCls : 'fa fa-search',
                btnCls: 'topjui-btn-normal',
                handler : function() {
                    list_search();
                }
            },'-', {
                text:'刷新',
                iconCls : 'fa fa-refresh',
                btnCls: 'topjui-btn-green',
                handler : function() {
                    listgrid.datagrid('reload');
                }
            }],
            onDblClickRow :function(rowIndex,rowData){
                list_lookFun(rowData.id);
            }
        });
    });
    function list_lookFun(id) {
        listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : "/contract/form",
            width : 900,
            height : 530,
            modal : true,
            title : '查看信息',
            onClose : function() {
                $(this).dialog('destroy');
            },
            onLoad : function() {
                var index = listgrid.datagrid('getRowIndex', id);
                var rows = listgrid.datagrid('getRows');
                var o = rows[index];
                $('#customerform').form('load', o);
                console.log(o);
                $('#form-sign').combotree({
                    width: 300,
                    height: 24,
                    style: "width:300px;height:26px;",
                    cls: 'selectp',
                    panelWidth: 300,
                    hasDownArrow: true,
                    url: '/user/xs',
                    required: true
                });
                $("input[name=sign]").val(o.signman);
                $("#form-signmanid").val(o.signmanid);

                $(".combo-text").removeAttr("style");
                $(".combo-text").attr("style", "width: 300px;height: 26px;;line-height:26px");
                $(".combo-text").addClass("selectp");
                $(".combo-arrow").attr("style", "margin-left: -20px;margin-top: 5px;background-color:rgba(0,0,0,0)");
                $(".combo-panel").attr("style", "margin-top:10px;");
            }
        });
    }

    function list_search(){
        $('<div/>').dialog({
            href : '/contract/delsearch',
            width : 370,
            height : 210,
            modal : true,
            title : '查询',
            buttons : [{
                text : '查询',
                iconCls : 'fa fa-search',
                btnCls: 'topjui-btn-normal',
                handler : function() {
                    var d = $(this).closest('.window-body');
                    var param = form2Json("search_form");
                    $('#search_form').form('submit', {
                        url : '/contract/list',
                        onSubmit:function(){
                            return true;
                        },
                        success : function(result) {
                            try {
                                var r = $.parseJSON(result);
                                listgrid.datagrid({
                                    url:'/contract/list',
                                    pagination : true,
                                    idField : 'id',
                                    pageSize : 20,
                                    pageList : [ 20, 50, 100 ],
                                    sortName : 'id',
                                    sortOrder : 'desc',
                                    queryParams: param,　　//关键之处
                                    data:r
                                });
                                d.dialog('destroy');

                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            }],
            onClose : function() {
                $(this).dialog('destroy');
            }
        });
    }

    function list_deleteFun(code) {
        listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $.messager.confirm('确认', '您是否要删除当前选中的项目？', function (r) {
            if (r) {
                $.ajax({
                    url: '/contract/delall',
                    data: {
                        code: code
                    },
                    dataType: 'json',
                    success: function (r) {
                        if (r.statusCode=='200') {
                            listgrid.datagrid('load');
                            listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
                        }
                        $.messager.show({
                            title: '提示',
                            msg: r.message
                        });
                    }
                });
            }
        });
    }
</script>

</body>
</html>